package com.freak.freakmusic.model.homepage

import com.freak.kotlinhttpmanager.kotlinhttpmanager.RxPresenter
import com.freak.kotlinhttpmanager.kotlinhttpmanager.log.LogUtil
import com.ximalaya.ting.android.opensdk.datatrasfer.CommonRequest
import com.ximalaya.ting.android.opensdk.datatrasfer.IDataCallBack
import com.ximalaya.ting.android.opensdk.model.announcer.AnnouncerCategoryList
import com.ximalaya.ting.android.opensdk.model.category.CategoryList
import com.ximalaya.ting.android.opensdk.model.coldboot.ColdBootDetail
import com.ximalaya.ting.android.opensdk.model.coldboot.ColdBootTag
import com.ximalaya.ting.android.opensdk.model.coldboot.GenreList
import com.ximalaya.ting.android.opensdk.model.coldboot.SubGenreList

class HomepagePresenter : RxPresenter<HomepageContract.View>(), HomepageContract.Presenter {
    override fun getColdBootDetail(specificParams: Map<String, String>) {
        CommonRequest.getColdBootDetail(specificParams, object : IDataCallBack<ColdBootDetail> {
            override fun onSuccess(p0: ColdBootDetail?) {
                val stringBuffer = StringBuffer()

                for (item in p0!!.coldBootTagList) {
                    stringBuffer.append("$item\n")
                }
                LogUtil.e("冷启动标签详情\n$stringBuffer")
            }

            override fun onError(p0: Int, p1: String?) {
                LogUtil.e("错误信息$p0$p1")
            }

        })
    }

    override fun getAnnouncerCategoryList(specificParams: Map<String, String>) {
        CommonRequest.getAnnouncerCategoryList(
            specificParams,
            object : IDataCallBack<AnnouncerCategoryList> {
                override fun onSuccess(p0: AnnouncerCategoryList?) {
                    val stringBuffer = StringBuffer()

                    for (item in p0!!.list) {
                        stringBuffer.append("${item.vcategoryName}\n")
                    }
                    LogUtil.e("拉雅主播分类\n$stringBuffer")
                }

                override fun onError(p0: Int, p1: String?) {
                    LogUtil.e("错误信息$p0$p1")
                }

            })
    }

    override fun getColdBootTag(specificParams: Map<String, String>) {
        CommonRequest.getColdBootTag(specificParams, object : IDataCallBack<ColdBootTag> {
            override fun onSuccess(p0: ColdBootTag?) {
                val stringBuffer = StringBuffer()

                for (item in p0!!.coldBootTagList) {
                    stringBuffer.append("$item\n")
                }
                LogUtil.e("冷启动分类 ${p0.coldBootGenre}")
                LogUtil.e("冷启动二级分类 ${p0.coldBootGenre}")
                LogUtil.e("冷启动标签\n$stringBuffer")
            }

            override fun onError(p0: Int, p1: String?) {
                LogUtil.e("错误信息$p0$p1")
            }

        })
    }

    override fun getColdbootSubGenres(specificParams: Map<String, String>) {
        CommonRequest.getColdbootSubGenres(specificParams, object : IDataCallBack<SubGenreList> {
            override fun onSuccess(p0: SubGenreList?) {
                val stringBuffer = StringBuffer()

                for (item in p0!!.subgenreList) {
                    stringBuffer.append("$item\n")
                }
                LogUtil.e("冷启动二级分类\n$stringBuffer")
            }

            override fun onError(p0: Int, p1: String?) {
            }

        })
    }

    override fun getColdbootGenres(specificParams: Map<String, String>) {
        CommonRequest.getColdbootGenres(specificParams, object : IDataCallBack<GenreList> {
            override fun onSuccess(p0: GenreList?) {
                val stringBuffer = StringBuffer()
                LogUtil.d("" + p0!!.genreList)
                for (item in p0!!.genreList) {
                    stringBuffer.append("一级分类名称\n$item\n")
                }
                LogUtil.e("冷启动一级分类$stringBuffer")
            }

            override fun onError(p0: Int, p1: String?) {
            }

        })
    }

    override fun getCategories(specificParams: Map<String, String>) {

        CommonRequest.getCategories(specificParams, object : IDataCallBack<CategoryList> {
            override fun onSuccess(p0: CategoryList?) {
                LogUtil.d("获取成功" + p0!!.categories.toString())
                val stringBuffer = StringBuffer()
                for (item in p0.categories) {
                    stringBuffer.append("名称--》").append(item.categoryName).append("\n")
                }
                LogUtil.e("分类数据\n${stringBuffer.toString()}")
                mView?.getCategoriesSuccess(p0)
            }

            override fun onError(p0: Int, p1: String?) {
                LogUtil.d("获取失败" + p0 + p1)
            }

        }
        )
    }

    override fun test() {
        mView?.testSuccess()
    }

}